cc=gcc
all:run
inc_path=./inc
src_path=./src
lib_path=./lib

inc=$(foreach item,$(inc_path),-I$(item))
lib_l=$(foreach item,$(lib_path),-L$(item))
lib_a=$(foreach item,$(subst lib,,$(notdir $(basename $(filter %.a,$(shell find $(lib_path) -name "lib*"))))),-l$(item))
lib_so=$(foreach item,$(subst lib,,$(notdir $(basename $(filter %.so,$(shell find $(lib_path) -name "lib*"))))),-l$(item))

option=$(inc) $(lib_l) $(lib_so) $(lib_a)

src=$(shell find $(src_path) -name "*.c")
obj=$(patsubst ./src/%.c,./obj/%.o,$(src))

./obj/%.o:./src/%.c
	@mkdir $(dir $@)
	@$(cc) -c $^ -o $@ $(option)

workspace:$(obj)
	@$(cc) $^ -o $@ $(option)

run:workspace
	@./$<

clean:
	-rm workspace obj -rf

debug:
	@echo $(inc)
	@echo $(lib_l)
	@echo $(lib_a)
	@echo $(option)
	@echo $(src)
	@echo $(obj)

.PHONY:debug clean
